using GrapeCity.Forguncy.Commands;
using GrapeCity.Forguncy.Log;
using GrapeCity.Forguncy.Plugin;
using LiteVectorIndex.Engine;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text.Json;
using System.Threading.Tasks;

namespace LiteVectorIndex
{
    [Icon("pack://application:,,,/LiteVectorIndex;component/Resources/Icon.png")]
    [Category("嵌入式向量库")]
    [OrderWeight(900)]
    public class Cluster_Destory : Command, ICommandExecutableInServerSideAsync
    {
        [FormulaProperty]
        [DisplayName("集合名")]
        public object KBName { get; set; }

        public async Task<ExecuteResult> ExecuteAsync(IServerCommandExecuteContext dataContext)
        {
            var name = (await dataContext.EvaluateFormulaAsync(KBName))?.ToString() ?? "";
            
            // 移除前先判断
            if (CollectionManager.Instance.CollectionExists(name))
            {
                dataContext.Log.AppendLine($"向量集合：{name} 已经被加载到内存，执行移除操作。");
                CollectionManager.Instance.RemoveCollection(name);
            }

            return new ExecuteResult();
        }

        public override string ToString()
        {
            return "嵌入式向量库：销毁向量集合";
        }

        public override CommandScope GetCommandScope()
        {
            return CommandScope.ExecutableInServer;
        }

    }
}
